package com.zhiyume.api.controller;

import com.zhiyume.service.common.ConstantEnum;
import com.zhiyume.dao.entity.TExtension;
import com.zhiyume.dao.entity.TSplash;
import com.zhiyume.dto.BaseResponse;
import com.zhiyume.service.ExtentsionService;
import com.zhiyume.service.SplashService;
import com.zhiyume.vo.SplashVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by wang on 17/11/27.
 */
@RestController
@Api(tags = "开屏及banner")
public class SplashAction {

    @Autowired
    private SplashService splashService;

    @Autowired
    private ExtentsionService extentsionService;

    @RequestMapping(value = "/api/splash",method = RequestMethod.GET)
    @ApiOperation(value = "开屏信息")
    public BaseResponse getSplash(){

        BaseResponse baseResponse = new BaseResponse();
        //查询条件
        TSplash search = new TSplash();
        //查询结果
        TSplash result = new TSplash();
        try{
            result = splashService.getLastSplash(search);
            baseResponse.setErrMsg("");
        }catch (Exception e){
            baseResponse.setErrMsg(ConstantEnum.CONSTANT_SYS_ERROR.getErrMsg());
            baseResponse.setErrType(ConstantEnum.CONSTANT_SYS_ERROR.getErrType());
        }

        baseResponse.setData(result);
        return baseResponse;
    }

    @RequestMapping(value = "/api/extension",method = RequestMethod.GET)
    @ApiOperation(value = "开屏信息")
    public BaseResponse getExtension(){

        BaseResponse baseResponse = new BaseResponse();

        SplashVO result = new SplashVO();
        try{
            TSplash tSplash = splashService.getLastSplash(new TSplash());
            BeanUtils.copyProperties(tSplash, result);
            TExtension tExtension = new TExtension();
            tExtension.setId(tSplash.getFromId());
            TExtension extension = extentsionService.getExtentsion(tExtension);
            BeanUtils.copyProperties(extension, result);

            baseResponse.setErrMsg("");
        }catch (Exception e){
            baseResponse.setErrMsg(ConstantEnum.CONSTANT_SYS_ERROR.getErrMsg());
            baseResponse.setErrType(ConstantEnum.CONSTANT_SYS_ERROR.getErrType());
        }

        baseResponse.setData(result);
        return baseResponse;
    }


}
